package com.example.tys.daggermvp;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.example.tys.daggermvp.mvp.base.BaseModule;
import com.example.tys.daggermvp.mvp.base.BasePresenter;
import com.example.tys.daggermvp.mvp.base.BaseView;

import javax.inject.Inject;

import dagger.android.support.DaggerFragment;

/**
 * support.DaggerFragment, Dagger注入。对应v4.app.Fragment
 *
 * @author tys
 * @date 2018/4/18
 */

public class BaseFragment<P extends BasePresenter, V extends BaseView, D extends BaseModule> extends DaggerFragment {
    @Inject
    protected P mPresenter;
    @Inject
    protected D module;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPresenter .takeData(module);
    }


    @Override
    public void onResume() {
        super.onResume();
        if (this instanceof BaseView) {
            mPresenter.takeView((V) this);
        }
    }

    @Override
    public void onDestroy() {
        mPresenter.drop();
        super.onDestroy();
    }

}
